package com.zhangxin.sunnyweather.ui.Place

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.zhangxin.sunnyweather.logic.Repository
import com.zhangxin.sunnyweather.logic.model.Place
import androidx.lifecycle.switchMap

class PlaceViewModel : ViewModel() {

    private val searchLivedata = MutableLiveData<String>()

    val placeList = ArrayList<Place>()

    val placeLiveData=searchLivedata.switchMap{ query ->
        Repository.searchPlaces(query)
    }


    fun searchPlaces(query:String){
        searchLivedata.value=query
    }

    fun savePlace(place: Place) = Repository.savePlace(place)

    fun getSavedPlace() = Repository.getPlace()
    fun isPlaceSaved() = Repository.isPlaceSaved()

}